package karileet.meeting.profile.free;

import android.content.Context;
import android.content.SharedPreferences;
import android.media.AudioManager;

/**
 * Class stores and reads user initial configuration
 * 
 * @author markus karileet
 */
public class UserConf {
	private static String USERCONF = "usermode";
	private AudioManager am;
	private Context ctx;
	
	public UserConf(Context ctx) {
		am = (AudioManager) ctx.getSystemService(Context.AUDIO_SERVICE);
		this.ctx = ctx;
	}
	
	/**
	 * Method sets ringer mode
	 * @param int mode
	 */
	public void set(int mode) {
		am.setRingerMode(mode);
	}
	
	/**
	 * Method stores ringerMode to shared preferences
	 * @return
	 */
	public boolean save() {
		SharedPreferences p = ctx.getSharedPreferences(MainActivity.PREFS_NAME, 0);
		p.edit().putInt(USERCONF, am.getRingerMode()).commit();
		return true;
	}
	
	/**
	 * Method retrieves ringer mode
	 * @return int
	 */
	public int get() {
		return am.getRingerMode();
	}
	
	/**
	 * Method reads ringer mode from shared preferences
	 * @return int
	 */
	public int read() {
		SharedPreferences p = ctx.getSharedPreferences(MainActivity.PREFS_NAME, 0);
		return p.getInt(USERCONF, AudioManager.RINGER_MODE_NORMAL);
	}
}
